package com.hzit.irs.shiro;

import com.hzit.irs.mapper.AdminMapper;
import com.hzit.irs.model.TbAdmin;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 */
@Component
public class ShiroRealm extends AuthorizingRealm {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 授权，角色，权限放到shiro
     * @param principalCollection
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {




        return null;
    }


    /**
     * 认证 用户对象放到shiro
     * @param authenticationToken
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {

        //获取用户名
        String username = (String) authenticationToken.getPrincipal();

        //根据用户名去查询
        TbAdmin tbAdmin = new TbAdmin();
        tbAdmin.setUsername("admin");
        tbAdmin.setPassword("e10adc3949ba59abbe56e057f20f883e");

        AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(tbAdmin,"e10adc3949ba59abbe56e057f20f883e","myRealm");




        return authenticationInfo;
    }
}
